<template>
  <div id="topSearch">
    <h1 class="con-right-title">
      关注热门推荐
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="用户属性" prop="userType">
          <el-select
            v-model="formInline.userType"
            placeholder="真实用户"
            clearable
          >
            <el-option
              v-for="item in userPropertyList"
              :key="item.key"
              :label="item.key"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="查询类型" prop="type">
          <el-select v-model="formInline.type" placeholder="手机号">
            <el-option
              v-for="item in searchTypeList"
              :key="item.dictLabel"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- 输入搜索部分 -->
        <el-form-item label="查询" prop="value">
          <el-input
            v-model="formInline.value"
            placeholder="手机号/用户名/QQ/大鹏号搜索"
            size="small"
            class="numberInput"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'TopSearch',
  msg: '热门推荐-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          userType: '', // 用户属性,默认全部
          type: '', // 查询类型,默认手机号
          value: '' // 查询
        }
      }
    }
  },
  data() {
    return {
      rules: {
        userType: {},
        type: {},
        value: {}
      },
      // 用户属性列表
      userPropertyList: [
        { key: '全部', value: '' },
        { key: '真实用户', value: 'REALUSER' },
        { key: '马甲用户', value: 'VESTUSER ' }
      ],
      // 查询类型列表
      searchTypeList: []
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    /* 获取置顶类型 */
    async getStatusList() {
      this.searchTypeList = await sysNormalDisable(
        'sys_user_search_type',
        'hotType'
      )
      this.searchTypeList.splice(3, 2)
      //设置默认数据
      this.setDefaultValue()
      //触发列表获取权限
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.type = this.searchTypeList[0].dictValue
    },
    // 重置
    reset() {
      this.$refs['ruleForm'].resetFields()
      //设置默认数据
      this.setDefaultValue()
    },
    // 搜索
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style lang="less">
#topSearch {
  .search-box {
    padding-left: 30px !important;
  }
}
.numberInput {
  width: 200px !important;
}
</style>
